﻿@using System.Text
@using OA.Model
@using OA.AspNetCore.Html
@using OA.Core.Model
@using OA.Core.Helper

@model PageList<SimpleKnowledge>
@{
    ViewBag.Title = "知识列表";
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
}
<div class="layui-tab layui-tab-brief" lay-filter="user">
    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 5px 0;">
        <form action="" class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="keyWord" placeholder="请输入往来单位搜索" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn searchButton">搜索</button>
                <a class="layui-btn" href="javascript:ShowPage('/Management/RelatedCompany/Create','添加往来单位')">添加往来单位</a>
            </div>
        </form>
    </div>
    <table class="layui-table" lay-data="{url:'GetData', cellMinWidth: 80, page: true,limit:15}" id="resultList" lay-filter="resultList">
        <thead>
            <tr>
                <th lay-data="{field:'ID', width:80, align:'center'}">ID</th>
                <th lay-data="{ field: 'Name',width:200}">单位名称</th>
                <th lay-data="{width:180,field: 'NO'}">编号</th>

                <th lay-data="{field:'LegalPerson', width:160}">法人</th>
                <th lay-data="{field:'BankOfDeposit', width:150}">开户银行</th>
                <th lay-data="{width:150,field: 'BankAccount'}">银行账号</th>
                <th lay-data="{width:120,field: 'Tel'}">电话</th>
                <th lay-data="{field:'IsSupplier',width:80,templet: '#IsSupplier'}">供应商</th>
                <th lay-data="{field:'IsCustomer',width:80,templet: '#IsCustomer'}">客户</th>
                <th lay-data="{fixed: 'right', width:220, align:'center', toolbar: '#barDemo'}">操作</th>
            </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:ShowPage('/Management/RelatedCompany/ShowContact?id={{d.ID}}','查看联系人')">查看联系人</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:ShowPage('/Management/RelatedCompany/Edit?id={{d.ID}}','编辑往来单位')">编辑</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:DeleteItem({{d.ID}})">删除</a>

    </script>
    <script type="text/html" id="IsSupplier">
        <input type="checkbox" lay-skin="primary" lay-filter="IsSupplier" {{d.IsSupplier?'checked':''}} value="{{d.ID}}" />
    </script>
    <script type="text/html" id="IsCustomer">
        <input type="checkbox" lay-skin="primary" lay-filter="IsCustomer" {{d.IsCustomer?'checked':''}} value="{{d.ID}}" />
    </script>
</div>
<script type="text/javascript">
    function DeleteItem(id) {
        layer.confirm('您正在进行删除往来单位操作', {
            btn: ['是的,我要删除该往来单位', '不小心点错了'] //按钮
        }, function () {
            var url = "/Management/RelatedCompany/Delete?id=" + id;
            $.getJSON(url, function (data) {
                layer.msg(data.Msg);
                if (data.State === 200) {
                    $(".layui-laypage-btn")[0].click();
                }                 
            });
        }, function () {

        });
    }
    layui.use(['table', 'layer', 'form'], function () {
        var table = layui.table;
        var form = layui.form;

        form.on('checkbox(IsSupplier)', function (data) {
            var isChecked = data.elem.checked;
            url = "/Admin/RelatedCompany/SetIsSupplier?id=" + data.value + "&status=" + data.elem.checked;
            $.getJSON(url, function (data) {
                if (data.State == 200) {
                    if (isChecked) {
                        layer.msg("设置为供应商成功", { time: 500 });
                    }
                    else {
                        layer.msg("供应商标识取消成功", { time: 500 });
                    }
                }
                else {
                    layer.msg(data.Msg);
                }
            });
        });

        form.on('checkbox(IsCustomer)', function (data) {
            var isChecked = data.elem.checked;
            url = "/Admin/RelatedCompany/SetIsCustomer?id=" + data.value + "&status=" + data.elem.checked;
            $.getJSON(url, function (data) {
                if (data.State == 200) {
                    if (isChecked) {
                        layer.msg("设置为客户成功", { time: 500 });
                    }
                    else {
                        layer.msg("客户标识取消成功", { time: 500 });
                    }
                }
                else {
                    layer.msg(data.Msg);
                }
            });
        });

    });
</script>


